
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class VendingMachineItemTest {

	//Declaring variable of type VendingMachineItem
	VendingMachineItem vmitem;        
	
	//creating new instance of VendingMachineItem before running a test case
	@Before          
	public void setUp() throws Exception {   
		
		vmitem = new VendingMachineItem("pepsi", 2.0);          
		} 
	
	//testing if the VendingMachineItem() works when a price zero is passed
		@Test        
		public void testVendingMachineItem_zeroPrice() {  
			vmitem = new VendingMachineItem("pepsi", 0.0);  
			assertEquals(0.0, vmitem.getPrice(), 0);          
			}
	
		//testing if the VendingMachineItem() works when a price zero is passed
		@Test (expected = VendingMachineException.class)
		public void testVendingMachineItem_lessThanZeroPrice() {  
			vmitem = new VendingMachineItem("pepsi", -2);  
			assertEquals(-2, vmitem.getPrice(), 0);          
			}
	@Test
	public void testGetName() {
		//creating object of class VendingMachineItem and using the constructor to initialize the name an the price
		VendingMachineItem item1=new VendingMachineItem("skittles", 2.5);
		// testing getName to make sure that the name is assigned correctly  
		assertEquals("skittles", item1.getName());
	}

	@Test
	public void testGetPrice() {
		//creating object of class VendingMachineItem and using the constructor to initialize the name an the price
		VendingMachineItem item1=new VendingMachineItem("skittles", 2.5);
		// testing getName to make sure that the name is assigned correctly 
		assertEquals(2.5, item1.getPrice(),0.0001);
	}
	
	//Clearing any previous value of vmi_item after a test case completed running
	@After          
	public void TearDown() throws Exception 	{                  
		vmitem = null;          
		} 
	
}
